package org.demo.ribbon.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: jack
 * \* Date: 2019/1/24
 * \* Time: 14:41
 * \* Description:
 * \
 */
@Service
public class HelloService {

    @Autowired
    RestTemplate restTemplate;

    // 加上熔断器注解
    @HystrixCommand(fallbackMethod = "fallBackHello")
    public String hello(String requestName){
        return  restTemplate.getForObject("http://eureka-client/hello/"+requestName,String.class);
    }

    public String fallBackHello(String requestName){
        return requestName+ "请求错误!";
    }
}
